import { defHttp } from '@/utils/http';
import { root } from '../apiRoot';
import type { IQuery, IResData } from '../indexTypes';
import type {
  AppUserCouponOrderMemberListData,
  AppUserCouponOrderMemberListResult,
  CardMemberCouponListData,
  CardMemberCouponListResult,
  MemberCouponAddData,
  MemberCouponDetailsResult,
  MemberCouponDisplayData,
  MemberCouponListData,
  MemberCouponListResult,
  MyCouponHistoryDetailsResult,
  ReceiveCouponData,
  ReceivedCouponResult,
} from './types';

const Api = {
  memberCouponList: root + 'member-coupon/member/pageList',
  cardMemberCouponList: root + 'member-coupon/app/pageList',
  memberCouponAdd: root + 'member-coupon/member/add',
  memberCouponDisplay: root + 'member-coupon/member/display',
  receivedCoupon: root + 'app-user-coupon-order/my/pageList',
  myCouponHistoryDetails: root + 'member-coupon/member/getByIdDetails',
  memberCouponDetails: root + 'member-coupon/app/getByIdInfo',
  receiveCoupon: root + 'app-user-coupon-order/app/claimCoupon',
  appUserCouponOrderMemberList: root + 'app-user-coupon-order/member/pageList',
  verificationOrder: root + 'app-user-coupon-order/member/verification'
};

/**
 * @description 优惠券 - 我发布的列表
 * @date 24/11/2022
 * @export
 * @param {IQuery} data
 */
export function memberCouponList(data: MemberCouponListData) {
  return defHttp.get<IResData<MemberCouponListResult>>({
    url: Api.memberCouponList,
    data,
  });
}

/**
 * @description 优惠券 - 我领取的
 * @date 24/11/2022
 * @export
 * @param {IQuery} data
 */
export function receivedCoupon(data: IQuery) {
  return defHttp.get<IResData<ReceivedCouponResult>>({
    url: Api.receivedCoupon,
    data,
  });
}

/**
 * @description 个人名片 - 福利券列表
 * @date 24/11/2022
 * @export
 * @param {CardMemberCouponListData} data
 */
export function cardMemberCouponList(data: CardMemberCouponListData) {
  return defHttp.get<IResData<CardMemberCouponListResult>>({
    url: Api.cardMemberCouponList,
    data,
  });
}

/**
 * @description 优惠券详情
 * @date 24/11/2022
 * @export
 * @param {number} id
 */
export function memberCouponDetails(id: number) {
  return defHttp.get<MemberCouponDetailsResult>({
    url: Api.memberCouponDetails + `/${id}`,
  });
}

export function myCouponHistoryDetails(id: number) {
  return defHttp.get<MyCouponHistoryDetailsResult>({
    url: Api.myCouponHistoryDetails + `/${id}`,
  });
}

/**
 * @description 新增优惠券
 * @date 24/11/2022
 * @export
 * @param {MemberCouponAddData} data
 */
export function memberCouponAdd(data: MemberCouponAddData) {
  return defHttp.post({
    url: Api.memberCouponAdd,
    data,
  });
}

/**
 * @description 优惠券 上架/下架
 * @date 24/11/2022
 * @export
 * @param {MemberCouponDisplayData} data
 */
export function memberCouponDisplay(data: MemberCouponDisplayData) {
  return defHttp.post({
    url: Api.memberCouponDisplay,
    data,
  });
}

/**
 * @description 领取优惠券
 * @date 24/11/2022
 * @export
 * @param {ReceiveCouponData} data
 */
export function receiveCoupon(data: ReceiveCouponData) {
  return defHttp.post({
    url: Api.receiveCoupon,
    data,
  });
}

/**
 * @description 获取 核销列表 / 领取记录
 * @date 25/11/2022
 * @export
 * @param {AppUserCouponOrderMemberListData} data
 */
export function appUserCouponOrderMemberList(data: AppUserCouponOrderMemberListData) {
  return defHttp.get<IResData<AppUserCouponOrderMemberListResult>>({
    url: Api.appUserCouponOrderMemberList,
    data,
  });
}

/**
 * @description 核销优惠券
 * @date 25/11/2022
 * @export
 * @param {{ couponOrderIds: number[] }} data
 */
export function verificationOrder(data: { couponOrderIds: number[] }) {
  return defHttp.post({
    url: Api.verificationOrder,
    data
  })
}